<script type="text/javascript">
    //检测门店名称或手机号是否存在
    layui.use(['layer', 'upload'], function () {
        var form = layui.form,
            upload = layui.upload;
        $(".edit-shop").blur(function () {
            var type = $(this).attr('name');
            var value = $(this).val();
            var id = $(this).attr('this-id');

            var that = $(this);
            $.ajax({
                type: "GET",
                url: "shop-author-data-monitoring?type=" + type + "&value=" + value + "&id=" + id,
                dataType: "json",
                success: function (obj) {
                    if (obj.state == 1) {
                        layer.msg(obj.msg, {time: 2000, icon: 5});
                        that.val('');
                    }
                }, error: function () {
                    alert("发生错误：");
                }
            });
        });

        //多图片上传
        upload.render({
            elem: '#up_banner'
            , url: 'admin-upload-img'
            , acceptMime: 'image/jpg, image/png, image/jpeg'
            , multiple: true
            , size: 1024
            , number: 5
            , done: function (res) {
                if (res.code == 0) {
                    var num = $('.imgNum').length;
                    var imgdta = '<span class="img-list">' +
                        '<img src="' + res.url + '" height="100" width="150" class="imgNum">' +
                        '<input type="hidden" name="img[' + num + ']" value="' + res.src + '">' +
                        '<i class="layui-icon close">ဆ</i></span>';
                    $('#up_banner').before(imgdta);
                    up_num();
                }
            }
        });
        $(document).on('click', '.close', function () {
            $(this).parent().remove();
            up_num();
        });

        //获取区域坐标
        form.on('select(area)', function (data) {
            var areaId = "{{$detail['area']}}";
            var oldLon = "{{$detail['longitude']}}";
            var oldLat = "{{$detail['latitude']}}";

            $.ajax({
                url: js_url('shop-area-coordinate'),
                type: 'post',
                data: {id: data.value},
                dataType: "json",
                success: function (result) {
                    if (areaId == data.value) {
                        $('#longitude').val(oldLon);
                        $('#latitude').val(oldLat);
                    }else{
                        $('#longitude').val(result.Lng);
                        $('#latitude').val(result.Lat);
                    }
                }
            });
        });

    });

    up_num();

    //上传图片数量限制
    function up_num() {
        var num = $('.imgNum').length;
        if (num >= 5) {
            $('#up_banner').hide();
        } else {
            $('#up_banner').show();
        }
        $('.img_num').val(num);
    }

    //统计列表数量
    function listNum() {
        var num = $('.make').length - 1;
        if (num > 0) {
            $('.del').show();
        } else {
            $('.del').hide();
        }
        $('.make').each(function (i) {
            if (num == i) {
                $(this).show();
            } else {
                $('.make').hide();
            }
        });

        layui.use(['laydate'], function () {
            var laydate = layui.laydate;
            lay('.day').each(function () {
                laydate.render({
                    elem: this,
                    trigger: 'click'
                });
            });
        });
    }

    //坐标拾取
    $(document).on('click', '#parentIframe', function () {
        var lon = $('#longitude').val();
        var lat = $('#latitude').val();
        if (lon && lat) {
            var lonlat = lon + ',' + lat;
        } else {
            var lonlat = '';
        }

        layer.open({
            type: 2,
            title: false,
            area: ['1000px', '500px'],
            shade: 0.8,
            closeBtn: 0,
            shadeClose: true,
            content: 'shop-author-openMap?lonlat=' + lonlat
        });
    });

    //添加服务类型
    $(document).on('click', '.add_type', function () {
        var daIn = $('.imgNum').length;
        var type = '<div class="layui-input-inline type-list">' +
            '<input type="text" name="service[' + daIn + '][title]" value="" lay-verify="required" class="layui-input imgNum">' +
            '<i class="layui-icon close" onclick="$(this).parent().remove();">ဆ</i>' +
            '</div>';
        $(this).before(type);
        up_num();
    });


</script>